//
//  ZMessageTableViewCell.m
//  WeClubs
//
//  Created by KevinWang on 17/6/20.
//  Copyright © 2017年 Zed. All rights reserved.
//

#import "ZMessageCenterCell.h"
#import "ZMessageCenterModel.h"

@interface ZMessageCenterCell ()
@property(nonatomic,strong) UIImageView *icon;
@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) UILabel *messageLabel;
@property(nonatomic,strong) UILabel *timeLabel;
@property(nonatomic,strong) UILabel *unreadLabel;



@end

@implementation ZMessageCenterCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //被选中的样式
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView{
    //add subview
    self.icon = [[UIImageView alloc] init];
    [self.contentView addSubview:self.icon];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.font = kFont(17);
    self.titleLabel.textColor = FONT_MAIN_COLOR;
    [self.contentView addSubview:self.titleLabel];
    
    self.messageLabel = [UILabel new];
    self.messageLabel.font = kFont(14);
    self.messageLabel.textColor = FONT_THIRD_COLOR;
    [self.contentView addSubview:self.messageLabel];
    
    self.timeLabel = [UILabel new];
    self.timeLabel.font = kFont(14);
    self.timeLabel.textColor = FONT_THIRD_COLOR;
    [self.contentView addSubview:self.timeLabel];
    
    self.unreadLabel = [UILabel new];
    self.unreadLabel.backgroundColor = [UIColor redColor];
    self.unreadLabel.layer.cornerRadius = 10.0f;
    self.unreadLabel.textColor = [UIColor whiteColor];
    self.unreadLabel.font = kFont(8);
    self.unreadLabel.textAlignment = NSTextAlignmentCenter;
    self.unreadLabel.layer.masksToBounds = YES;
    [self.contentView addSubview:self.unreadLabel];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    //layout
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(8);
        make.height.width.mas_equalTo(52);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon);
        make.left.equalTo(self.icon.mas_right).offset(12);
    }];
    
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.contentView).offset(-112);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon);
        make.right.equalTo(self.contentView).offset(-12);
    }];
    
    [self.unreadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.messageLabel);
        make.right.equalTo(self.timeLabel);
    }];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"cell";
    ZMessageCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[ZMessageCenterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (void)setMessageCenterModel:(ZMessageCenterModel *)messageCenterModel{
    _messageCenterModel = messageCenterModel;
}

@end
